//
//  SINATecScroInputViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/2.
//  Copyright © 2018年  androidlongs. All rights reserved.
//  成绩录入 

#import "SINATecScroInputViewController.h"
#import "SINATecManagerQuerScoreItemTableViewCell.h"
#import "SINASubClassModel.h"
#import "SINATecManagerScoreInputDetailViewController.h"

@interface SINATecScroInputViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic)  UITableView *mainContentTableView;
@property (strong, nonatomic)  UILabel *noDataLabel;
@property(nonatomic,strong) NSMutableArray *dataList;
@end

@implementation SINATecScroInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"成绩录入";
    
    for (NSInteger i=0; i<0; i++) {
       
        [self.dataList addObject:@"i"];
    }
    
    self.mainContentTableView.delegate=self;
    self.mainContentTableView.dataSource=self;
    self.mainContentTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.mainContentTableView.backgroundColor=[UIColor colorWithHexString:@"#fafafa"];
    self.mainContentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.mainContentTableView];
    
    [self loadingSubClassNetData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSMutableArray *)dataList{
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return  _dataList;
}
-(UITableView *)mainContentTableView{
    if (!_mainContentTableView) {
        _mainContentTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH)];
    }
    return _mainContentTableView;
}
-(UILabel *)noDataLabel{
    if (!_noDataLabel) {
        _noDataLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH)];
        _noDataLabel.text = @"暂无数据";
        _noDataLabel.textAlignment = NSTextAlignmentCenter;
        _noDataLabel.font=[UIFont systemFontOfSize:14];
        _noDataLabel.textColor=[UIColor grayColor];
        [self.view addSubview:_noDataLabel];
    }
    return _noDataLabel;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    SINATecManagerQuerScoreItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SINATecManagerQuerScoreItemTableViewCell"];
    
    if (cell == nil) {
        cell= [[[NSBundle mainBundle]loadNibNamed:@"SINATecManagerQuerScoreItemTableViewCell" owner:nil options:nil] firstObject];
        
    }
    cell.itemClickBlock = ^(SINASubClassModel *model) {
        
        SINATecManagerScoreInputDetailViewController *controller=[[SINATecManagerScoreInputDetailViewController alloc]initWithNibName:@"SINATecManagerScoreInputDetailViewController" bundle:nil];
        controller.mode = model;
        [self.navigationController pushViewController:controller animated:YES];
        
    };
    cell.model = self.dataList[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 117;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
//    NSInteger index = indexPath.row;

}


-(void)loadingSubClassNetData{

    [self startLoading];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    [dict setObject:[[SINACommonUserHelper share]getUserModel].userUid forKey:@"teacheruuid"];
    WeakSelf;
    
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@",baseUrl,getClassifyAndSubjectByTeacherUuidUrl] withParamters:dict success:^(id responseData) {
        
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            NSMutableArray *result = responseData[@"content"];
            if (result!=nil&&result.count>0) {
                for (NSInteger i=0; i<result.count; i++) {
                    NSDictionary *dict=result[i];
                    SINASubClassModel *model = [[SINASubClassModel alloc]initWithDict:dict];
                    [self.dataList addObject:model];
                }
                self.noDataLabel.hidden=YES;
                self.mainContentTableView.hidden=NO;
                [self.mainContentTableView reloadData];
            }else{
                self.noDataLabel.hidden=NO;
                self.mainContentTableView.hidden=YES;
            }
            
        }else{
//            NSString *message =responseData[@"message"];
//            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
//                                                                 cancleBtn:nil];
            //[alertView showXLAlertView];
            self.noDataLabel.hidden=NO;
             self.mainContentTableView.hidden=YES;
        }
        
        
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败  %@ ",error.debugDescription);
        [weakSelf stopLoading];
//        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"加载数据失败" sureBtn:@"确定"
//                                                             cancleBtn:nil];
        //[alertView showXLAlertView];
        self.noDataLabel.hidden=NO;
         self.mainContentTableView.hidden=YES;
    }];
}
@end
